<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont.css" />
		<style>
			html,
			body {
				background-color: #efeff4;
				margin: 0px;
				padding: 0px;
				height: 100%;
			}
			.mui-bar-nav span{
				display: none;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="tab_go mui-icon mui-icon-map mui-pull-right" href="maps.html">
				<span class="mui-tab-label">地图</span>
			</a>
			<a class="tab_go mui-icon iconfont icon-xiangce mui-pull-right" style="margin-right: 10px;" href="gallery.html">
				<span class="mui-tab-label">相册</span>
			</a>
			<h1 id="title" class="mui-title">技能</h1>
		</header>
		<nav class="mui-bar mui-bar-tab">
			<nav class="mui-bar mui-bar-tab">
				<a class="tab_go mui-tab-item mui-active" href="tab-skill.html">
					<span class="mui-icon iconfont icon-jineng"></span>
					<span class="mui-tab-label">技能</span>
				</a>
				<a class="tab_go mui-tab-item" href="tab-project.html">
					<span class="mui-icon iconfont icon-xiangmu"></span>
					<span class="mui-tab-label">项目</span>
				</a>
				<a class="tab_go mui-tab-item" href="tab-work.html">
					<span class="mui-icon iconfont icon-inauguration"></span>
					<span class="mui-tab-label">经历</span>
				</a>
				<a class="tab_go mui-tab-item" href="tab-me.html">
					<span class="mui-icon iconfont icon-jianjie"></span>
					<span class="mui-tab-label">我</span>
				</a>
			</nav>
			<script src="js/mui.min.js"></script>
			<script type="text/javascript" charset="utf-8">
				//mui初始化
				mui.init();
				var subpages = ['tab-skill.html', 'tab-project.html', 'tab-work.html', 'tab-me.html', 'maps.html', 'gallery.html'];
				var subpage_style = {
					top: '45px',
					bottom: '51px'
				};

				var aniShow = {};

				//创建子页面，首个选项卡页面显示，其它均隐藏；
				mui.plusReady(function() {
					var self = plus.webview.currentWebview();
					for(var i = 0; i < subpages.length; i++) {
						var temp = {};
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
						if(i > 0) {
							sub.hide();
						} else {
							temp[subpages[i]] = "true";
							mui.extend(aniShow, temp);
						}
						self.append(sub);
					}
				});
				//当前激活选项
				var activeTab = subpages[0];
				var title = document.getElementById("title");
				//选项卡点击事件
			/*	mui('.mui-bar-nav').on('tap', 'a', function(e) {
					var targetTab = this.getAttribute('href');
					if(targetTab == activeTab) {
						return;
					}
					//更换标题
					title.innerHTML = this.innerHTML;
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 300);
					}
					//隐藏当前;
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
*/
				mui('body').on('tap', '.tab_go', function(e) {
					var targetTab = this.getAttribute('href');
					if(targetTab == activeTab) {
						return;
					}
					//更换标题
					title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 300);
					}
					//隐藏当前;
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
				//自定义事件，模拟点击“首页选项卡”
				document.addEventListener('gohome', function() {
					var defaultTab = document.getElementById("defaultTab");
					//模拟首页点击
					mui.trigger(defaultTab, 'tap');
					//切换选项卡高亮
					var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
					if(defaultTab !== current) {
						current.classList.remove('mui-active');
						defaultTab.classList.add('mui-active');
					}
				});

				window.addEventListener('refresh', function(e) { //执行刷新
					location.reload();
				});
			</script>
	</body>

</html>